//
//  SettingViewController.m
//  QuickCure
//
//  Created by haoge on 16/9/10.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "SettingViewController.h"
#import "WZDViewController.h"
#import "LeftViewController.h"

@interface SettingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,weak) UITableView *tableView;

@property (nonatomic,copy) NSArray *dataArray;

@end

static NSString *indentifier = @"cell";

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
}

//懒加载
- (NSArray *)dataArray
{
    if (nil == _dataArray)
    {
        _dataArray = [NSArray arrayWithObjects:@"意见反馈",@"加号符号说明",@"修改密码",@"注销用户", nil];
    }
    
    return _dataArray;
}

- (void)setupUI
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    
    tableView.tableFooterView = [[UIView alloc] init];
    
    tableView.dataSource = self;
    
    tableView.delegate = self;
    
    [self.view addSubview:tableView];
    
}

#pragma mark -- 实现数据源方法.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    
    cell.textLabel.text = self.dataArray[indexPath.row];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

#pragma mark -- 实现代理方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        WZDViewController *vc = [[WZDViewController alloc] init];
        
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row == 3)
    {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"想跑?" message:@"门都没有啊" preferredStyle:UIAlertControllerStyleActionSheet];
        
        UIAlertAction *sure = [UIAlertAction actionWithTitle:@"😁,来追我啊~" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
           
            //取到根控制器
            JASidePanelController *rootVC = (JASidePanelController *)[UIApplication sharedApplication].keyWindow.rootViewController;
            
            //根据根控制器取到左侧控制器
            LeftViewController *leftVC = (LeftViewController *)rootVC.leftPanel;
            
            //设置为登录状态
            leftVC.isLogin = NO;
            
        }];
        
        [alertController addAction:sure];
        
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"我还不走了呢!" style:UIAlertActionStyleCancel handler:NULL];
        
        [alertController addAction:cancel];
        
        [self presentViewController:alertController animated:YES completion:nil];
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
